<?php

namespace app\common\cachemodel\chakra;

use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

class ChakraCrystalGoodsType extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.chakra_crystal_goods_type';

    protected $cacheModel = 'chakra.crystal_goods_type';

    /**
     * 获取所有类型数据
     * @return array|mixed
     * @throws \Exception
     */
    public function getGoodTypeData()
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel)->getDataAndSet(function ()
        {
            try
            {
                $data = $this->where(['status' => 1])->order("sort desc")->column('*', 'id');

                return json_encode(array_values($data), JSON_UNESCAPED_UNICODE);
            }
            catch (\Exception $e)
            {
                \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
                return '';
            }
        });

        return $data ? json_decode($data, true) : [];
    }
}